package homework.test2;

import java.io.*;
import java.net.Socket;

public class ClientDemo2 {
    public static void main(String[] args) throws IOException {
        //1.客户端确定连接
        Socket sk = new Socket("127.0.0.1",10002);

        //2.客户端输出
        OutputStreamWriter osw = new OutputStreamWriter(sk.getOutputStream());
        BufferedWriter bw = new BufferedWriter(osw);
        bw.write("只因登场");
        bw.newLine();
        bw.write("怕了吧");
        bw.flush();
       bw.newLine();
//        sk.shutdownOutput();

        //7.从服务器接收
        BufferedReader br = new BufferedReader(new InputStreamReader(sk.getInputStream()));
        String s;
        while ((s = br.readLine()) != null) {
            System.out.println("服务器:"+s);
        }

        //8.释放
        br.close();
        sk.close();
    }
}
